package com.zk.algorithm.string;

import com.zk.algorithm.annotation.Easy;
import com.zk.algorithm.annotation.LeetCodeExplore;

/**
 * @author zk
 */
@Easy
@LeetCodeExplore
public class FirstUniqueCharacterInAString {

    public int firstUniqChar(String s) {
        if (s == null || s.isEmpty()) {
            return -1;
        }

        int[] countMap = new int[26];
        for (char c : s.toCharArray()) {
            countMap[c - 'a']++;
        }

        for (int i = 0; i < s.length(); i++) {
            if (countMap[s.charAt(i) - 'a'] == 1) {
                return i;
            }
        }

        return -1;
    }

}
